package com.mijie.homi.service.session;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mijie.homi.common.constant.MCKey;
import com.mijie.homi.common.domain.session.Session;
import com.mijie.homi.service.cache.MemcacheService;

@Service
public class SessionService {

	@Autowired
	private MemcacheService mcs;
	
	private Logger logger = Logger.getLogger(SessionService.class);
	
	public Integer getUserIdByToken(String token){
		Session session = (Session) mcs.get(MCKey.SESSION,token);
		return session==null?null:session.getUserId();
	}
	
	public Session getSessionByUserId(int userId){
		String token = (String) mcs.get(MCKey.TOKEN_BY_USERID, String.valueOf(userId));
		if(token==null) return null;
		return (Session) mcs.get(MCKey.SESSION,token);
	}
}
